#include "../include/Operation.h"

static const Operation empty;

QVector<Operation>* Operation::operationList()
{
	static QVector<Operation>* qvo = new QVector<Operation>();
	return qvo;
}

const Operation& Operation::findOperation(
	const QString& identifier,
	uint num_args,
	bool* found)
{
	static QVector<Operation>& ol = *operationList();
	QVector<Operation>::const_iterator it = ol.begin();
	for ( ; it != ol.end(); ++it) {
		if (identifier == it->d->identifier) {
			if (num_args == it->d->num_args or num_args == VARIABLE_ARG_LIST) {
				if (found) { *found = true; }
				return *it;
			}
		}
	}
	if (found) { *found = false; }
	return empty;
}

void Operation::addOperation(const Operation& op)
{
	static QVector<Operation>& ol = *operationList();
	ol.append(op);
}
